package com.shixun.milktea.controller;



import com.shixun.milktea.entity.Manager;

import com.shixun.milktea.service.ManagerService;
import com.shixun.milktea.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zrs
 * @since 2022-06-07
 */
@RestController
@Api(tags = "管理员相关接口")
public class ManagerController {
    @Autowired
    ManagerService managerService;

    @GetMapping("/manager/findAllManager")
    @ApiOperation(value = "查询所有管理员")
    public ResultVO selectManager() throws Exception {
        List<Manager> managers = managerService.selectList();
        return new ResultVO(managers);
    }

    @PostMapping("/manager/saveManager")
    @ApiOperation(value = "添加管理员")
    public ResultVO saveManager(@RequestBody Manager manager) throws Exception {
        managerService.saveAdmin(manager);
        return new ResultVO(manager);
    }


    @PostMapping("/login")
    @ApiOperation(value = "管理员登录")
    public ResultVO Login(@RequestParam("username") String username,@RequestParam("password") String password) throws Exception {
        UserDetails userDetails = managerService.loadUserByUsername(username);

        return new ResultVO(userDetails);
    }

}
